#pragma once
#include<time.h>
#include<iostream>
#include"Graph_Functions.h"
#include<algorithm>
#include"Tests.h"
#include<queue>
#include"2-SAT.h"
#include <stdexcept>

vector<pair<int, int> > random_2sat_problem(int size, int num)
{
	vector<pair<int, int> > problem;
	for(int step = 0; step < num; ++step)
	{
		int a = rand()%size + 1;
		int b = rand()%size + 1;
		if (rand()%2 == 1)a = -a;
		if (rand()%2 == 1)b = -b;
		problem.push_back(make_pair(a, b));
	}
	return problem;
}

bool check(vector<bool> &Values, vector<pair<int, int> > &Note)
{
	for(int cur_str = 0; cur_str < Note.size(); ++cur_str)
	{
		bool first = false;
		bool second  = false;
		if (Note[cur_str].first > 0 && Values[Note[cur_str].first]) first = true;
		if (Note[cur_str].first < 0 && !Values[-Note[cur_str].first]) first = true;

		if (Note[cur_str].second > 0 && Values[Note[cur_str].second]) second = true;
		if (Note[cur_str].second < 0 && !Values[-Note[cur_str].second]) second = true;

		if (!first && !second)return false;
	}
	return true;
}

bool check_not_existing(int size, vector<pair<int, int> > &Note)
{
	int Big = 1 << size;
	for(int examp = 0; examp < Big; ++examp)
	{
		int examp1 = examp;
		vector<bool>cur_values;
		cur_values.push_back(1);
		for(int ind = 1; ind <= size; ++ind)
		{
			cur_values.push_back(examp1%2);
			examp1 /= 2;
		}
		if (check(cur_values, Note))
		{
			cerr << "Crushed on:\n";
			for(int cur = 1; cur <= size; ++cur)
				cerr << cur << ": " << cur_values[cur] << "\n";
		}
	}
return true;
}

void Mega_2SAT_Check()
{
	for(int size = 2; size <= 10; ++size, cerr << size << "\n")
		for(int num = 1; num <= 100; ++num)
		{
			vector<pair<int, int> > Note = random_2sat_problem(size, num);
			vector<bool> Values = TwoSAT(size, Note);
			if (!Values[0])
			{
<<<<<<< .mine
				if (!check_not_existing(size, Note))cout << "THIS ALGHORITHM IS INCORRECT! OLOLOLOLOLOLOLOLIOLOLOLOLOLOOLOLOLOLOLOLOLOLOLOLOLO\n";
			}
=======
				cout << Note[cur_str].first << " " << Note[cur_str].second << "\n";
			}*/
			vector<bool> Values = TwoSAT(size, Note);
			if (!Values[0])
			{
				//cout << "NOT EXISTS!\n"; 
				if (!check_not_existing(size, Note))cout << "THIS ALGHORITHM IS INCORRECT! OLOLOLOLOLOLOLOLIOLOLOLOLOLOOLOLOLOLOLOLOLOLOLOLOLO\n";
			}
>>>>>>> .r86
			else 
			{
				if (!check(Values, Note)) cout << "THIS NUMBERS DONT PASS THROUGH THE CHECK!\n";
			}
<<<<<<< .mine
=======
			//cout << "\n";
>>>>>>> .r86
		}


}